import { useEffect } from "react";
import { useState } from "react";
import axios from 'axios';
function Cate(){
    // 定义商品分类列表
    let [cateList,setList] = useState([]);
    let [goodsList,setGoods] = useState([]);
    useEffect(()=>{
        axios.get(`https://apif.java.crmeb.net/api/front/category`).then(res=>{
            console.log(res)
            setList(res.data.data)
            getList(res.data.data[0].id)
        })
    },[])
    // 获取商品列表
    function getList(cid){
        axios.get(`https://apif.java.crmeb.net/api/front/products?page=1&limit=10&type=1&cid=${cid}`).then(res=>{
            console.log(res)
            setGoods(res.data.data.list)
        })
    }
    return <div>
         <div>
            {
                cateList.map(item=>{
                    return <span key={item.id} onClick={()=>getList(item.id)}>{item.name}</span>
                })
            }
         </div>
    </div>
}


export default Cate;